/************************************************************************
** This class is the main class that do almost everything related to 
** menus and toolbars. 
*************************************************************************/

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QtGui/QMainWindow>
#include <QtGui/QLineEdit>
#include "DElementDelegate.h"
class APnMView;
class QAction;
class QMenu;
class QToolBar;
class QMdiArea;
class QMdiSubWindow;
class QSignalMapper;
class QTreeView;

class MainWindow : public QMainWindow
{
	Q_OBJECT

public:
	MainWindow(QWidget *parent = 0, Qt::WFlags flags = 0);
	~MainWindow();

protected:
	void closeEvent(QCloseEvent *event);

private slots:
	void test(); //just for test

	void newFile();
	void open();
	void openFile(const QString & noSuffix);
	void save();
	void saveAs();
	void print();
	void cut();
	void copy();
	void paste();
	void del();
	void about();
	void updateMenus();
	void updateWindowMenu();
	APnMView *createAPnMView();
	void setActiveSubWindow(QWidget *window);

	//engine
	void engineConf();

	// view on the Scientific Workflow Application
	void compositeUp();
	void compositeDown();

	// control on the tokens in a Pool of the Scientific Workflow 
	void setTokenMode(bool tokenMode);
	void setRunMode(bool runMode);
	void tryEngine(bool connect);

	// control on the Scientific Workflow Application
	void play();
	void pause();
	void stop();
	void reverse_play();
	void forward();
	void backward();

private:
	void createActions();
	void createMenus();
	void createToolBars();
	void createStatusBar();
	void readSettings();
	void writeSettings();
	APnMView *activeAPnMView();
	QMdiSubWindow *findAPnMView(const QString &fileName);

	QMdiArea *mdiArea;
	QSignalMapper *windowMapper;

	QMenu *fileMenu;
	QMenu *editMenu;	
	QMenu *windowMenu;
	QMenu *helpMenu;
	QToolBar *fileToolBar;
	QToolBar *editToolBar;
	QAction *newAct;
	QAction *openAct;
	QAction *saveAct;
	QAction *saveAsAct;
	QAction *printAct;
	QAction *exitAct;
	QAction *cutAct;
	QAction *copyAct;
	QAction *pasteAct;
	QAction *delAct;
	QAction *closeAct;
	QAction *closeAllAct;
	QAction *tileAct;
	QAction *cascadeAct;
	QAction *nextAct;
	QAction *previousAct;
	QAction *separatorAct;
	QAction *aboutAct;
	QAction *aboutQtAct;

	//Engine
	QToolBar *engineToolBar;

	// control
	QMenu *apnmMenu;
	QToolBar *apnmToolBar;
	QAction *upAct;
	QAction *downAct;
	QAction *tokenAct;
	QAction *engineAct;

	//run-time toolbar
	QToolBar *runToolBar;
	QAction *playAct;
	QAction *pauseAct;
	QAction *stopAct;
	QAction *reverse_playAct;
	QAction *forwardAct;
	QAction *backwardAct;

	// view of Actors, Routers, Pools, Composites
	QTreeView *actorView;
	QTreeView *routerView;
	QTreeView *poolView;
	QTreeView *compositeView;
private:
	// load model value, respectively(actor, router, and pool) 
	bool loadModel(QTreeView* view, const QString& file);

	QLineEdit* mHostEdit;
	QLineEdit* mPortEdit;
	QString mHost;
	quint16 mPort;
};

#endif // MAINWINDOW_H
